﻿@{
    ViewBag.Title = "Khóa học";
    Layout = "~/Views/Shared/FrontEndMasterLayout.cshtml";
    MvcHtmlString str = new MvcHtmlString("class=\"odd\"");
    string classOwner = "";
    if (Request.QueryString["ClassOwner"] != null &&
        Request.QueryString["ClassOwner"].Trim() != "" && Request.QueryString["ClassOwner"].Trim() != "Tên người mở lớp")
    {
        classOwner = Request.QueryString["ClassOwner"].Trim();
    }
    Guid categoryID = Guid.Empty;
    if (Request.QueryString["CategoryID"] != null &&
        Request.QueryString["CategoryID"].Trim() != "")
    {
        categoryID = Guid.Parse(Request.QueryString["CategoryID"].Trim());
    }
}
@using DLULearningNetworkModel
@model DLULearningNetwork.ViewModels.ListCoursesViewModel
@section cssjs{
    <link rel="Stylesheet" type="text/css" href="../../Content/Site.css" />
    <link rel="Stylesheet" type="text/css" href="../../Content/icon.css" />
    <script type="text/javascript" src="../../Scripts/Custom/jsCourse.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            Course.init();
        });
    </script>
}
@section rightColumn{
    <div style="width: 730px;">
        <div class="TieuDe">
            Danh sách khóa học
            <div style="float: right;">
                <a href="/Course/Create" style="font-size: 14px;"><span>Mở
                    khóa học</span></a>
            </div>
        </div>
        <div class="clearall">
        </div>
        <div>
            <div style="float: left;">
                <a class="personal_nocolor_icon36" href="/Course/Personal">Cá nhân</a> <a class="public_icon36"
                    href="/Course/Community" style="padding-left: 44px;">Cộng đồng</a>
            </div>
            <div style="float: right;">
                @using (Html.BeginForm("Community", "Course", FormMethod.Get, new { id = "frmSearch" }))
                {
                    List<Category> categories = Category.GetAll();                
                    <span class="text_1" style="line-height: 36px;">Lĩnh vực</span>
                    <select id="ddlCategoryID" name="CategoryID" style="height: 22px;">
                        @if (categoryID == Guid.Empty)
                        {
                            <option value="" selected="selected">Tất cả</option>
                        }
                        else
                        {
                            <option value="">Tất cả</option>
                        }
                        @for (int i = 0; i < categories.Count; i++)
                        {
                            if (categoryID == categories[i].CategoryID_u)
                            {
                            <option value="@categories[i].CategoryID_u" selected="selected">@categories[i].Name_s</option>    
                            }
                            else
                            {
                            <option value="@categories[i].CategoryID_u">@categories[i].Name_s</option>    
                            }
                        }
                    </select>
                        if (classOwner == "")
                        {
                    <input id="txtClassOwner" name="ClassOwner" type="text" value="Tên người mở lớp"
                        style="height: 20px; color: #999;" />
                        }
                        else
                        {
                    <input id="txtClassOwner" name="ClassOwner" type="text" value="@classOwner" style="height: 20px" />
                        }
                    <input type="submit" class="button1" value="Tìm kiếm" />
                }
            </div>
        </div>
        <div class="clearall">
        </div>
        <div id="tableData">
            <div id="loading" class="loading">
            </div>
            <table class="tbl1" cellspacing="0" style="margin-top: 10px;">
                <tr>
                    <th style="width: 350px;">
                        Tên
                    </th>
                    <th>
                        Lĩnh vực
                    </th>
                    <th>
                        Người mở lớp
                    </th>
                    <th>
                    </th>
                </tr>
                @for (int i = 0; i < Model.Courses.Count; i++)
                {
                    <tr @if (i % 2 != 0)
                        { @str } courseID="@Model.Courses[i].CourseID_u" style="height:32px;">
                        <td>@Model.Courses[i].Title_s
                        </td>
                        <td>@Model.Courses[i].Category.Name_s
                        </td>
                        <td>@Model.Courses[i].Account.Nickname_s
                        </td>
                        <td style="text-align: center;">
                            @if (Course.Single(DLULearningNetwork.Controllers.FrontEndBaseController.LoginUser.AccountID_u, Model.Courses[i].CourseID_u) == null)
                            {
                                Enrollment enrollment = Enrollment.Single(DLULearningNetwork.Controllers.FrontEndBaseController.LoginUser.AccountID_u, Model.Courses[i].CourseID_u);
                                if (enrollment != null)
                                {
                                    if (enrollment.Status_i == 1)
                                    {
                                <a href="/Course/Wall/@Model.Courses[i].CourseID_u"><span title="Vào lớp học" class="enter_icon24"
                                    style="cursor: pointer;"></span></a>
                                    }
                                    else if (enrollment.Status_i == 0)
                                    {
                                <span title="Đang chờ phê duyệt" class="waiting_icon24"></span>
                                    }
                                    else
                                    {
                                <span style="color: #ff0000;">Đã bị từ chối</span>
                                    }
                                }
                                else
                                {
                                <span title="Đăng ký tham gia" class="register_icon24" style="cursor: pointer;">
                                </span>
                                }
                            }
                            else
                            {
                                <a href="/Course/Wall/@Model.Courses[i].CourseID_u"><span class="manager_icon24"
                                    title="Quản lý khóa học" style="cursor: pointer;"></span></a>
                            }
                        </td>
                    </tr>
                }
            </table>
            <div class="pagination pagination-left" style="margin-left: 3px;">
                <ul class="pager">
                    @Html.Partial("UCPager2", new DLULearningNetwork.ViewModels.PagerViewModel2(Model.TotalItems, DLULearningNetwork.Libs.Constants.DEFAULT_PAGESIZE, DLULearningNetwork.Libs.Constants.DEFAULT_COURSES_PERPAGE,
                                 Model.CurrentPage, Request.Url.AbsoluteUri))
                </ul>
            </div>
        </div>
    </div>
}
